package com.bw.miaosha.conf;

import com.bw.miaosha.vo.UserVo;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author: 朱财艺
 * @date : 2022/02/24
 * @Description:
 */
@Component
public class MyInterceptor implements HandlerInterceptor {

  public static  ThreadLocal<String> userVoThreadLocal = new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//      Cookie[] cookies = request.getCookies();
//      for (Cookie cookie : cookies) {
//        String name = cookie.getName();
//        if ("userkey".equals(name)){
//          userVoThreadLocal.set(name);
//        }
//      }
      return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
